// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   baseInfo_ok.java

package ecommerce.website;

import com.jspsmart.upload.*;
import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class baseInfo_ok extends HttpServlet
{

	public baseInfo_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			ServletContext context = session.getServletContext();
			String path = context.getRealPath("/");
			counter count = new counter(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			nseer_db_backup1 ecommerce_db = new nseer_db_backup1(dbApplication);
			if (ecommerce_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				mySmartUpload.initialize(pageContext);
				String file_type = getFileLength.getFileType((String)session.getAttribute("unit_db_name"));
				long d = getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				try
				{
					mySmartUpload.upload();
					getAttachmentLength getAttachmentLength = new getAttachmentLength();
					getAttachmentType getAttachmentType = new getAttachmentType();
					String file_name[] = new String[mySmartUpload.getFiles().getCount()];
					String not_change[] = new String[mySmartUpload.getFiles().getCount()];
					String attachment[] = mySmartUpload.getRequest().getParameterValues("attachment");
					String unit_id = mySmartUpload.getRequest().getParameter("unit_id");
					String delete_file_name[] = new String[0];
					String sql1 = (new StringBuilder("select * from ecommerce_web_base where unit_id='")).append(unit_id).append("'").toString();
					ResultSet rs = ecommerce_db.executeQuery(sql1);
					if (rs.next())
					{
						if (attachment != null)
						{
							delete_file_name = new String[attachment.length];
							for (int i = 0; i < attachment.length; i++)
								delete_file_name[i] = rs.getString(attachment[i]);

						}
						for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						{
							SmartFile file = mySmartUpload.getFiles().getFile(i);
							if (file.isMissing())
							{
								file_name[i] = "";
								int q = i + 1;
								String field_name = (new StringBuilder("attachment")).append(q).toString();
								if (!rs.getString(field_name).equals(""))
									not_change[i] = "yes";
							} else
							{
								int filenum = count.read((String)dbSession.getAttribute("unit_db_name"), "ecommerceAttachmentcount");
								count.write((String)dbSession.getAttribute("unit_db_name"), "ecommerceAttachmentcount", filenum);
								file_name[i] = (new StringBuilder(String.valueOf(filenum))).append(file.getFileName()).toString();
								file.saveAs((new StringBuilder(String.valueOf(path))).append("ecommerce/file_attachments/").append(filenum).append(file.getFileName()).toString());
							}
						}

					}
					String name = mySmartUpload.getRequest().getParameter("name");
					String title = mySmartUpload.getRequest().getParameter("title");
					String advertisement1 = mySmartUpload.getRequest().getParameter("advertisement1");
					String advertisement2 = mySmartUpload.getRequest().getParameter("advertisement2");
					String webmaster_email = mySmartUpload.getRequest().getParameter("webmaster_email");
					String icp = mySmartUpload.getRequest().getParameter("icp");
					String register = mySmartUpload.getRequest().getParameter("register");
					String register_ID = mySmartUpload.getRequest().getParameter("register_ID");
					String register_time = mySmartUpload.getRequest().getParameter("register_time");
					String content = new String(mySmartUpload.getRequest().getParameter("content").getBytes("UTF-8"), "UTF-8");
					String copyright = new String(mySmartUpload.getRequest().getParameter("copyright").getBytes("UTF-8"), "UTF-8");
					String sqla = (new StringBuilder("update ecommerce_web_base set name='")).append(name).append("',title='").append(title).append("',advertisement1='").append(advertisement1).append("',advertisement2='").append(advertisement2).append("',content='").append(content).append("',copyright='").append(copyright).append("',icp='").append(icp).append("',register='").append(register).append("',register_ID='").append(register_ID).append("',register_time='").append(register_time).append("',webmaster_email='").append(webmaster_email).append("'").toString();
					String sqlb = (new StringBuilder(" where unit_id='")).append(unit_id).append("'").toString();
					if (attachment != null)
					{
						for (int i = 0; i < attachment.length; i++)
						{
							sqla = (new StringBuilder(String.valueOf(sqla))).append(",").append(attachment[i]).append("=''").toString();
							File file = new File((new StringBuilder(String.valueOf(path))).append("ecommerce/file_attachments/").append(delete_file_name[i]).toString());
							file.delete();
						}

					}
					for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++)
						if (not_change[i] == null || !not_change[i].equals("yes"))
						{
							int p = i + 1;
							sqla = (new StringBuilder(String.valueOf(sqla))).append(",attachment").append(p).append("='").append(file_name[i]).append("'").toString();
						}

					String sql = (new StringBuilder(String.valueOf(sqla))).append(sqlb).toString();
					ecommerce_db.executeUpdate(sql);
					response.sendRedirect("ecommerce/website/baseInfo_b.jsp");
				}
				catch (Exception ex)
				{
					response.sendRedirect("ecommerce/website/baseInfo_a.jsp");
				}
				ecommerce_db.commit();
				ecommerce_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
